package com.mtsmda.java.xml.jaxb;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import com.mtsmda.Country;
import com.mtsmda.State;

public class JaxbJavaToXML {

	public static void main(String[] args) {
		State state = new State("Chisinau", new Long(750_000));
		State state1 = new State("Belity", new Long(150_000));
		List<State> states = new ArrayList<>();
		states.add(state);
		states.add(state1);
		Country country = new Country("Moldova", new Double(3_500_000), states);
		System.out.println(country);

		try {
			JAXBContext jaxbContext = JAXBContext.newInstance(Country.class);
			Marshaller marshaller = jaxbContext.createMarshaller();

			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
					Boolean.TRUE);
			File fileXML = new File("countries.xml");

			marshaller.marshal(country, fileXML);

			marshaller.marshal(country, System.out);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}